
function removeFromArray(array: any[], item: any) {
  let index = array.indexOf(item);

  if (index >= 0) {
    array.splice(index, 1);
  }
}

class DataTransfer {

  dropEffect: string = 'none'
  effectAllowed: string = 'all'
  types: any[] = []
  files: any[] = []
  dataByFormat: any = {}


  clearData(dataFormat: string) {
    if (dataFormat) {
      delete this.dataByFormat[dataFormat];
      removeFromArray(this.types, dataFormat);
    } else {
      this.dataByFormat = {};
      this.types = [];
    }
  }

  getData(dataFormat: string) {
    return this.dataByFormat[dataFormat];
  }

  setData(dataFormat: string, data: any) {
    this.dataByFormat[dataFormat] = data;

    if (this.types.indexOf(dataFormat) < 0) {
      this.types.push(dataFormat);
    }

    return true;
  }

  setDragImage() {
    // don't do anything (the stub just makes sure there is no error thrown if someone tries to call the method)
  }

}

export default DataTransfer
